package com.ruoyi.system.Control;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;

import java.io.File;
import java.io.IOException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.google.gson.Gson;
import com.ruoyi.system.Control.memberEnt;
import org.apache.commons.io.FileUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class HttpClientExample {

    // 读取json文件并解析为对象
    public static <T> T readJsonFile(String path, Class<T> valueType) {
        try {
            String jsonString = new String(Files.readAllBytes(Paths.get(path)));
            Gson gson = new Gson();
            return gson.fromJson(jsonString, valueType);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) throws IOException {

        // 示例使用
        File file =new File("D:\\result.json");
        String json1 = FileUtils.readFileToString(file, "UTF-8");



        // 输出响应内容
     //   System.out.println(response.body().string());
       //   String str =    (response.body().string());
        String str =  json1 ;

                //第一种方式
        Map maps = (Map)JSON.parse(str);
        System.out.println("这个是用JSON类来解析JSON字符串!!!");
        for (Object map : maps.entrySet()){
            if (((Map.Entry)map).getKey().equals("data")){
                System.out.println(((Map.Entry)map).getKey()+"     " + ((Map.Entry)map).getValue());
                String json = ((Map.Entry)map).getValue().toString() ;
                List<gonghuiEnt> res = null ;
                ObjectMapper objectMapper = new ObjectMapper();
                TypeReference< List<memberEnt> > typeRef = new TypeReference< List<memberEnt> >() {};
                List<memberEnt> list = objectMapper.readValue(json, typeRef);
                List<MemEnt> listgh = new ArrayList<MemEnt>() ;
                for (memberEnt  a: list) {
                   MemEnt tmp = new MemEnt();
                   tmp.setAreaCode(a.getAreaCode());
                  tmp.setCityName(a.getCityName());
                   tmp.setOrganId(a.getOrganId());
                   tmp.setName(a.getName());
                   tmp.setUserAge(a.getUserAge());
                   tmp.setOrganId(a.getOrganId());
                   listgh.add(tmp);
                }

            }

        }
    }
}